package com.mytest.offer;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public class SolutionJZ18 {

    public static void main(String[] args) {
        SolutionJZ18 solutionJZ6 = new SolutionJZ18();
        ListNode listNode = new ListNode(1);
        ListNode listNode1 = new ListNode(2);
        ListNode listNode2 = new ListNode(3);

        listNode.next = listNode1;
        listNode1.next = listNode2;

        solutionJZ6.deleteDuplication(listNode);
    }
    public ListNode deleteNode (ListNode head, int val) {
        ListNode res = new ListNode(0);
        //在链表前加一个表头
        res.next = head;
        ListNode cur = res;

        while(cur.next != null){
            if(cur.next.val == val){
                cur.next = cur.next.next;
                break;
            }
            cur = cur.next;
        }
        return res.next;
    }
    public ListNode deleteDuplication(ListNode pHead) {
        if(pHead == null){
            return null;
        }
        ListNode res = new ListNode(0);
        //在链表前加一个表头
        res.next = pHead;
        ListNode cur = res;
        while(cur.next != null && cur.next.next != null){

            if (cur.next.val == cur.next.next.val) {
                int temp = cur.next.val;
                while(cur.next != null && cur.next.val == temp){
                    cur.next = cur.next.next;
                }
            } else {
                cur = cur.next;
            }

        }
        return res.next;
    }
}
